package com.myosw.quartz;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.myosw.solr.FilterKeyword;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.myosw.jdbc.common.DBManager;
import com.myosw.pojo.Filter;
import com.myosw.pojo.Filterlog;
import com.myosw.pojo.POJO;

public class FilterJob implements Job {

	private static Logger _log = LoggerFactory.getLogger(FilterJob.class);
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		
		_log.info("执行作业： "+context.getJobDetail().getKey() +"  执行时间："+new Date()+"********************************");
		Filter bean = new Filter();
		List<Filter> list = (List<Filter>) bean.list();
		for (Filter filter : list) 
		{
			Filterlog filterlog = new Filterlog();
			filterlog.setFilter(filter.getId());
			filterlog.setCount(FilterKeyword.getcount(filter.getKeyword()));//总数
			filterlog.setNewcount((int) (filterlog.getCount()-filter.getCount()));//新添加数
			filterlog.setUpdatetime(new Timestamp(new Date().getTime()));
			filterlog.save();
			_log.info("添加 关键字过滤日志");
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("count", filterlog.getCount());
			map.put("newcount", filterlog.getNewcount());
			map.put("updatetime", filterlog.getUpdatetime());
			bean.update(map , filter.getId());
			
			_log.info("更新关键字统计");
			
		}
		//关闭数据库链接
		DBManager.closeConnection(); //释放数据库连接到连接池中

	}

}
